package com.lvyou.ctrl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lvyou.entity.UserModel;
import com.lvyou.model.JsonResult;
import com.lvyou.service.UserSrv;


@RestController
public class RegCtrl {

	@Resource(name="userSrv")
	private UserSrv userSrv;
	
	@PostMapping(value="doReg")
	public JsonResult doReg(@RequestParam String phone,@RequestParam String password){
		
		UserModel um=new UserModel();
		um.setPhone(phone);
		um.setPassword(password);
		
		JsonResult jr=new JsonResult(1,"注册成功！");
		
		try {
			List list=userSrv.queryByPhone(phone);
			if(list!=null && list.size()>0) {
				jr.setCode(101);
				jr.setMsg("电话号已经存在，不能注册！");
				return jr;
			}
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		try {
			userSrv.reg(um);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			jr.setCode(100);
			jr.setMsg("注册失败！");
		}
		
		
		return jr;
	}
}
